-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Add teleport checks for world bounds #13076
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
0556dbc to
e07c1a2
Compare
|
Current tests... @EventHandler
public void onPlayerTeleportEvent(org.bukkit.event.player.PlayerTeleportEvent event) {
event.setTo(event.getTo().clone().add(0, 29999999, 0));
}this allow me test a thing like |
| Preconditions.checkArgument(ServerLevel.isInSpawnableBounds(CraftLocation.toBlockPosition(event.getFrom())), "origin for PlayerTeleportEvent is out of spawnable bounds [x/z between %s and %s or y between %s and %s]", -ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MIN_ENTITY_SPAWN_Y, ServerLevel.MAX_ENTITY_SPAWN_Y); | ||
| if (!event.isCancelled()) { | ||
| Preconditions.checkArgument(ServerLevel.isInSpawnableBounds(CraftLocation.toBlockPosition(event.getTo())), "destination for PlayerTeleportEvent is out of spawnable bounds [x/z between %s and %s or y between %s and %s]", -ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MIN_ENTITY_SPAWN_Y, ServerLevel.MAX_ENTITY_SPAWN_Y); | ||
| } | ||
|
|
||
| return event; | ||
| } | ||
|
|
||
| public static PlayerTeleportEndGatewayEvent callPlayerTeleportEndGatewayEvent(ServerPlayer nmsPlayer, Location to, TheEndGatewayBlockEntity nmsTheEndGatewayBlockEntity) { | ||
| CraftPlayer entity = nmsPlayer.getBukkitEntity(); | ||
| PlayerTeleportEndGatewayEvent event = new PlayerTeleportEndGatewayEvent(entity, entity.getLocation(), to, new org.bukkit.craftbukkit.block.CraftEndGateway(nmsPlayer.level().getWorld(), nmsTheEndGatewayBlockEntity)); | ||
|
|
||
| event.callEvent(); | ||
|
|
||
| Preconditions.checkArgument(ServerLevel.isInSpawnableBounds(CraftLocation.toBlockPosition(event.getFrom())), "origin for PlayerTeleportEndGatewayEvent is out of spawnable bounds [x/z between %s and %s or y between %s and %s]", -ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MIN_ENTITY_SPAWN_Y, ServerLevel.MAX_ENTITY_SPAWN_Y); | ||
| if (!event.isCancelled()) { | ||
| Preconditions.checkArgument(ServerLevel.isInSpawnableBounds(CraftLocation.toBlockPosition(event.getTo())), "destination for PlayerTeleportEndGatewayEvent is out of spawnable bounds [x/z between %s and %s or y between %s and %s]", -ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MAX_LEVEL_SIZE, ServerLevel.MIN_ENTITY_SPAWN_Y, ServerLevel.MAX_ENTITY_SPAWN_Y); | ||
| } | ||
|
|
||
| return event; | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make a helper method to instead have to repeat all of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make a helper method to instead have to repeat all of this?
for take the event and check? if that then need remove that part where say what event is the issue in the Preconditions not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These checks should be in the event, otherwise the stacktrace is useless for plugins.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that values are not in the event (api) for make the checks in that...
Not sure how can manage this... If add a magic value in Locations and check or another better way
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the better way would be to move the event impl into the server like PaperInventoryMoveItemEvent for example or just a bridge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, lets make the event have a server implementation and check the bounds there. Checking the bounds after is an issue because exceptions thrown there aren't caught like ones thrown inside event handlers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then need make a impl for like 4 classes not?
a PaperPlayerTeleportEndGatewayEvent and PaperPlayerTeleportEvent (with the Entity side event) with a override in the set for add the check not?
e07c1a2 to
a54436a
Compare
Currently the API and events related to teleport allow put values out of bounds causing the player softlock or crash the servers (based in that coord is affected x/z or y) This PR make a check where teleport happens for throw an error before the change happen.
Closes #13023
Closes #13186